# coding=utf-8
"""
作者：董新强 
创建时间：
描述：
"""
from random import random

import numpy

from catsim import irt
from db_models.cat_questions import CatQuestions
from framework.utilities import to_string

if __name__ == '__main__':
    import re

    question_pattern = re.compile('^\d+[．.、]')
    options_pattern = re.compile('^[ABCD．.、]+')
    space = re.compile('\s+')


    def replace_opt_space(opt):
        opt = options_pattern.sub('', opt)
        if ' ' in opt:
            return space.sub('-', opt)
        return opt


    def new_question(answer, title, a, b, c, d):
        q = CatQuestions()
        q.a = random()
        q.b = min(0.3, q.a)
        q.c = 0.25
        q.d = 1
        q.answer = answer.lower()
        info = irt.max_info_hpc(numpy.array([[q.a, q.b, q.c, q.d]]))
        q.info = float(info[0])
        q.aid = 3
        q.type = 'MC4'
        q.exp_rate = 0.9

        q.title = title
        q.options = to_string([{"id": "a", "name": a}, {"id": "b", "name": b}, {"id": "c", "name": c}, {"id": "d", "name": d}])
        return q
